package io.zhengsh.juc._1lock.atomic;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

public class AtomicTest2 {

    public static AtomicInteger total = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch downLatch = new CountDownLatch(1000);
        for (int i = 0; i < 1000; i++) {
            new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    total.getAndIncrement();
                }
                downLatch.countDown();
            }).start();
        }
        downLatch.await();
        System.out.println(total.get());
    }
}
